package com.huawei.appgallery.share.activity;

import android.content.Context;
import android.text.TextUtils;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import com.huawei.appgallery.share.protocol.WXEntryActivityProtocol;
import com.huawei.appgallery.share.protocol.WXEntryActivityProtocol.Request;
import com.huawei.appmarket.support.emui.permission.BasePermissionActivity;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant.KeyAndValue;
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX.Req;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage.IMediaObject;
import com.tencent.mm.opensdk.modelmsg.WXWebpageObject;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import o.cfw;
import o.cvt;
import o.BaseRequest;
import o.cwj.i;
import o.cwr;
import o.cxd;
import o.cxo;
import o.cxr;
import o.dgh;
import o.dgu;
import o.diu;
import o.dof;
import o.ContentManager;
import o.evd;
import o.evk;

public class WXShareActivity extends BasePermissionActivity<WXEntryActivityProtocol> {
    private IWXAPI ʻॱ;
    private boolean ʾ = false;
    private cxd ˈ = new cxd(this) {
        final /* synthetic */ WXShareActivity ˏ;

        {
            this.ˏ = r1;
        }

        public void ˎ(Context context, String str, String str2) {
            this.ˏ.ॱˎ = str2;
            this.ˏ.ˊॱ();
            this.ˏ.ͺ();
        }
    };
    private String ˊॱ;
    private String ˏॱ;
    private String ͺ;
    private byte[] ॱˊ;
    private String ॱˎ;
    private int ॱᐝ;
    private int ᐝॱ;

    static class d implements IServerCallBack {
        private d() {
        }

        public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
        }

        public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
            int responseCode = responseBean.getResponseCode();
            if (responseCode == 0 && responseBean.getRtnCode_() != 0) {
                responseCode = 1;
            }
            if (responseBean.getResponseCode() == 0 && responseBean.getRtnCode_() == 0) {
                cxr.ˏ(0);
            } else if (3 == responseCode) {
                evk.ˏ(ContentManager.getInstant().getContext(), i.ʻ, 0).ˋ();
            } else if (ResponseBean.SERVER_DELAY_RETRY == responseCode) {
                cwr.ॱ.ˋ("WXShareActivity", "store access control");
            } else {
                evk.ˏ(ContentManager.getInstant().getContext(), i.ʽ, 0).ˋ();
            }
        }
    }

    public void ʼ() {
        getWindow().requestFeature(1);
        evd.ˏ(getWindow());
    }

    private void ᐝ() {
        WXEntryActivityProtocol wXEntryActivityProtocol = (WXEntryActivityProtocol) ʾ();
        if (wXEntryActivityProtocol == null) {
            finish();
            return;
        }
        Request ˏ = wXEntryActivityProtocol.ˏ();
        if (ˏ == null) {
            finish();
            return;
        }
        this.ˊॱ = ˏ.ˋ();
        this.ˏॱ = ˏ.ˊ();
        this.ͺ = ˏ.ˎ();
        this.ॱˊ = ˏ.ˏ();
        this.ॱᐝ = ˏ.ॱ();
        this.ᐝॱ = ˏ.ᐝ();
        cxo.ˎ(getString(i.ॱˎ), this, this.ˈ);
    }

    private void ͺ() {
        IMediaObject wXWebpageObject = new WXWebpageObject();
        wXWebpageObject.webpageUrl = this.ͺ;
        WXMediaMessage wXMediaMessage = new WXMediaMessage(wXWebpageObject);
        wXMediaMessage.title = this.ˊॱ;
        wXMediaMessage.description = this.ˏॱ;
        wXMediaMessage.thumbData = this.ॱˊ;
        Req req = new Req();
        req.transaction = ॱ("webpage");
        req.message = wXMediaMessage;
        req.scene = this.ॱᐝ;
        ॱ(req);
    }

    private void ॱ(Req req) {
        if (this.ʻॱ != null) {
            try {
                this.ʻॱ.sendReq(req);
                ॱˊ();
                return;
            } catch (Throwable e) {
                cwr.ॱ.ˊ("WXShareActivity", "error when share to wx.", e);
                finish();
                return;
            }
        }
        cwr.ॱ.ˊ("WXShareActivity", "wxShareApi is null.");
        finish();
    }

    private String ॱ(String str) {
        return dof.ʼ(str) + System.currentTimeMillis();
    }

    private void ˊॱ() {
        if (this.ʻॱ == null && !TextUtils.isEmpty(this.ॱˎ)) {
            this.ʻॱ = WXAPIFactory.createWXAPI(this, this.ॱˎ);
            this.ʻॱ.registerApp(this.ॱˎ);
            cwr.ॱ.ˋ("WXShareActivity", "init weixin api ! wxReqScene: " + this.ॱᐝ);
        }
    }

    private void ॱˊ() {
        String str;
        if (this.ॱᐝ == 0) {
            str = "02";
        } else if (this.ॱᐝ == 1) {
            str = KeyAndValue.NUMBER_01;
        } else {
            finish();
            return;
        }
        String userId = UserSession.getInstance().getUserId();
        dgh.onEvent(new o.dge.d(ContentManager.getInstant().getContext(), i.ˎ).ˏ(str + "|00|" + userId + '|' + this.ͺ).ˋ());
        cvt ˋ = dgu.ˋ("8", this.ͺ, this.ᐝॱ);
        ˋ.ˊ("WEIXIN");
        cfw.ˎ(ˋ, new d());
    }

    public void onDestroy() {
        super.onDestroy();
        if (this.ʻॱ != null) {
            this.ʻॱ.detach();
            this.ʻॱ = null;
        }
    }

    public void ॱॱ() {
        if (diu.ˊ().ˎ()) {
            ᐝ();
        } else {
            finish();
        }
    }

    public void onResume() {
        super.onResume();
        if (this.ʾ) {
            finish();
        }
        this.ʾ = true;
    }

    public boolean ॱᐝ() {
        return false;
    }
}
